package com.projectzqjz.parttimework.adapter;

import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.projectzqjz.parttimework.R;
import com.projectzqjz.parttimework.entity.PartSiftEntity;
import com.projectzqjz.parttimework.ui.fragment.PartMsgFragment;
import com.projectzqjz.parttimework.utils.ScreenUtil;

import java.util.ArrayList;
import java.util.List;

public class ScreenAccountAdapter extends BaseQuickAdapter<PartSiftEntity, BaseViewHolder> {
    private Activity activity;
    private int screenWidth;
    private int intervalWidth;
    private List<View> list_ll = new ArrayList<>();
    private List<TextView> list_tv = new ArrayList<>();

    public ScreenAccountAdapter(Activity activity, List<PartSiftEntity> list) {
        super(R.layout.item_screen, list);
        this.activity = activity;
        screenWidth = ScreenUtil.getScreenWidth(activity);
        intervalWidth = ScreenUtil.dip2px(activity, 47);
    }

    @Override
    protected void convert(BaseViewHolder helper, PartSiftEntity item) {
        LinearLayout ll_ = helper.getView(R.id.ll_gg);
        TextView ll_gg = helper.getView(R.id.tv_);
        if (helper.getPosition() == 0 && PartMsgFragment.accountSelected == -1) {
            ll_.setBackground(mContext.getResources().getDrawable(R.drawable.screen_select1));
        }
        if (PartMsgFragment.accountSelected == -1 && helper.getPosition() > 0) {
            ll_.setBackground(mContext.getResources().getDrawable(R.drawable.screen_normal1));
            ll_gg.setTextColor(mContext.getResources().getColor(R.color.color666));
        }

        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) ll_gg.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20

        linearParams.width = (screenWidth - intervalWidth) / 4;// 控件的宽强制设成30

        ll_gg.setLayoutParams(linearParams);
        ll_gg.setText(item.getNameValue());
        list_tv.add(ll_gg);
        list_ll.add(ll_);
        helper.getView(R.id.ll_gg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (int i = 0; i < list_ll.size(); i++) {
                    if (list_ll.get(i).equals(view)) {
                        PartMsgFragment.accountSelected = i;
                        ((TextView) list_tv.get(i)).setTextColor(mContext.getResources().getColor(R.color.colorFE6B2F));
                        list_ll.get(i).setBackground(mContext.getResources().getDrawable(R.drawable.screen_select1));
                    } else {
                        ((TextView) list_tv.get(i)).setTextColor(mContext.getResources().getColor(R.color.color666));
                        list_ll.get(i).setBackground(mContext.getResources().getDrawable(R.drawable.screen_normal1));
                    }
                }
            }
        });
    }
}
